/*
 * @Author: lineCode 1145938682@qq.com
 * @Date: 2025-01-04 16:35:25
 * @LastEditors: lineCode 1145938682@qq.com
 * @LastEditTime: 2025-06-26 12:28:28
 * @FilePath: /backend/shorthand-modules/shorthand-modules-content/src/main/java/com/angus/modules/content/repository/ENQuestionRepository.java
 */
package com.angus.modules.content.repository;
import com.angus.modules.content.domain.ENCourseQuestion;
import com.angus.modules.content.mapper.ENCourseQuestionMapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Objects;

/**
 * @author liyanan
 * @date 2024/11/24 7:00 PM
 * @description
 */
@Repository
public class ENQuestionRepository extends ServiceImpl<ENCourseQuestionMapper, ENCourseQuestion> {

    public List<ENCourseQuestion> getQuestionList(String courseCode, Integer questionType, Long groupId,Integer unitNum) {
        return baseMapper.selectList(Wrappers.lambdaQuery(ENCourseQuestion.class)
                .eq(ENCourseQuestion::getCourseCode, courseCode)
                .eq(ENCourseQuestion::getUnitNum, unitNum)
                .eq(ENCourseQuestion::getQuestionType, questionType)
                .eq(Objects.nonNull(groupId),ENCourseQuestion::getGroupId, groupId)
                .eq(ENCourseQuestion::getDelFlag, 0));
    }

    public Boolean getQuestion(String courseCode, Long groupId, String groupFlag, Integer questionType) {
        Long count = baseMapper.selectCount(Wrappers.lambdaQuery(ENCourseQuestion.class)
                .eq(ENCourseQuestion::getCourseCode, courseCode)
                .eq(ENCourseQuestion::getQuestionType, questionType)
                .eq(ENCourseQuestion::getGroupId, groupId)
                .eq(ENCourseQuestion::getGroupFlag, groupFlag)
                .eq(ENCourseQuestion::getDelFlag, 0));
        return count > 0;
    }

    public Boolean getQuestionByCourse(String courseCode, Integer questionType) {
        Long count = baseMapper.selectCount(Wrappers.lambdaQuery(ENCourseQuestion.class)
                .eq(ENCourseQuestion::getCourseCode, courseCode)
                .eq(ENCourseQuestion::getQuestionType, questionType)
                .eq(ENCourseQuestion::getDelFlag, 0));
        return count > 0;
    }
}
